package com.example.mobile2021606163crw0507;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private EditText edtMainPerson;
    private Button btnMainLogin;
    private EditText edtMainPassword;
    private Button btnMainEnd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btnMainLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (edtMainPerson.length() == 0 & edtMainPassword.length() == 0){
                    Toast.makeText(MainActivity.this,"用户名或者密码为空",Toast.LENGTH_SHORT).show();
                }else {
                    Intent intent = new Intent(MainActivity.this, ShowDataActivity.class);
                    String person = edtMainPerson.getText().toString().trim();
                    String password = edtMainPassword.getText().toString().trim();
                    intent.putExtra("person",person);

                    Bundle bundle = new Bundle();
                    bundle.putString("password",password);
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
            }
        });
        btnMainEnd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tvMainTitle);
        edtMainPerson = (EditText) findViewById(R.id.edtMainPerson);
        btnMainLogin = (Button) findViewById(R.id.btnMainLogin);
        edtMainPassword = (EditText) findViewById(R.id.edtMainPassword);
        btnMainEnd = (Button) findViewById(R.id.btnMainEnd);
    }
}